Make last row of new gallery not be huge.
authorBrian Wolff <bawolff+wn@gmail.com>
Wed, 21 Aug 2013 17:00:47 +0000 (10:00 -0700)
committerBrian Wolff <bawolff+wn@gmail.com>
Wed, 21 Aug 2013 23:52:45 +0000 (23:52 +0000)
If we cannot make the last row fit the page width,
make the image zoom factor be the average zoom
factor (sans any shrinking) so that the last
row doesn't have images that are super huge.

Change-Id: I0caf8d1800808f14c9f53073f3b901eedec32bb7

resources/mediawiki.page/mediawiki.page.gallery.js

index fd2af40..ddf63a8 100644 (file)
@@ -94,7 +94,9 @@
                                        $caption,
                                        hookInfo,
                                        i,
-                                       j;
+                                       j,
+                                       avgZoom,
+                                       totalZoom = 0;
 
                                for ( i = 0; i < rows.length; i++ ) {
                                        maxWidth = $gallery.width();
                                                // code, would prevent accidentally expanding to
                                                // be 10 billion pixels wide.
                                                mw.log( 'mw.page.gallery: Cannot fit row, aspect is ' + preferredHeight/curRowHeight );
-                                               preferredHeight = 1.5 * curRowHeight;
+                                               if ( i === rows.length - 1 ) {
+                                                       // If its the last row, and we can't fit it,
+                                                       // don't make the entire row huge.
+                                                       avgZoom = ( totalZoom / ( rows.length - 1 ) ) * curRowHeight;
+                                                       if ( isFinite( avgZoom ) && avgZoom >= 1 && avgZoom <= 1.5 ) {
+                                                               preferredHeight = avgZoom;
+                                                       } else {
+                                                               // Probably a single row gallery
+                                                               preferredHeight = curRowHeight;
+                                                       }
+                                               } else {
+                                                       preferredHeight = 1.5 * curRowHeight;
+                                               }
                                        }
                                        if ( !isFinite( preferredHeight ) ) {
                                                // This *definitely* should not happen.
                                                // Skip this row.
                                                continue;
                                        }
+
+                                       if ( preferredHeight / curRowHeight > 1 ) {
+                                               totalZoom += preferredHeight / curRowHeight;
+                                       } else {
+                                               // If we shrink, still consider that a zoom of 1
+                                               totalZoom += 1;
+                                       }
+
                                        for ( j = 0; j < curRow.length; j++ ) {
                                                newWidth = preferredHeight * curRow[j].aspect;
                                                padding = curRow[j].width - curRow[j].imgWidth;